package com.chuanke.ckfamily.service.common.model;

import java.io.Serializable;
import java.util.UUID;

/**
 * Created by wangbin on 2017/6/27.
 */
public class UserToken implements Serializable{

	private static final long serialVersionUID = 7044424561386473566L;

    public static final String KEY = "CFTOKEN_";

	public static final Long TIME_SPAN = 3600000l * 1000;

    private Long id;

    private String token;

    private String oldToken;

    private String newToken;

    private Long invalidateTime;

    public UserToken(Long id) {
        this.id = id;
        this.token = id + UUID.randomUUID().toString();
        invalidateTime = System.currentTimeMillis() + TIME_SPAN;
    }

    public UserToken(Long id, String token) {
        this.id = id;
        this.token = token;
        invalidateTime = System.currentTimeMillis() + TIME_SPAN;
    }

    public void refresh() {
        invalidateTime = System.currentTimeMillis() + TIME_SPAN;
    }

    public Long getId() {
        return id;
    }

    public String getToken() {
        return token;
    }

    public Long getInvalidateTime() {
        return invalidateTime;
    }

    public boolean isInvalidate() {
        return System.currentTimeMillis() < invalidateTime;
    }

    public String getOldToken() {
        return oldToken;
    }

    public void setOldToken(String oldToken) {
        this.oldToken = oldToken;
    }

    public String getNewToken() {
        return newToken;
    }

    public void setNewToken(String newToken) {
        this.newToken = newToken;
    }

	@Override
	public String toString() {
		return "UserToken [id=" + id + ", token=" + token + ", oldToken=" + oldToken + ", newToken=" + newToken
				+ ", invalidateTime=" + invalidateTime + "]";
	}
}
